<template>
    <div class="orderPage">
      <!-- header -->
      <div class="search_header">
        <van-nav-bar
          title="我的订单"
          left-arrow
          @click-left="$router.go(-1)"
        />
      </div>
      <!-- headerbar -->
      <div class="order_nav">
        <van-tabs :active="active">
          <van-tab title="全部" name="all"></van-tab>
          <van-tab title="待支付" name="payment"></van-tab>
          <van-tab title="待发货" name="delivery"></van-tab>
          <van-tab title="待收货" name="received"></van-tab>
          <van-tab title="待评价" name="comment"></van-tab>
        </van-tabs>
        <orderItem></orderItem>
      </div>
    </div>
</template>

<script>
import orderItem from '@/components/orderItem.vue'
import { getOrder } from '@/api/order'
export default {
  name: 'OrderIndex',
  data () {
    return {
      active: this.$route.query.dataType || 'all',
      page: 1,
      list: []
    }
  },
  created () {
    this.getOrder()
  },
  components: {
    orderItem
  },
  methods: {
    async getOrder () {
      const { data: { list } } = await getOrder(this.active, this.page)
      list.data.forEach((item) => {
        item.total_num = 0
        item.goods.forEach((goods) => {
          item.total_num += goods.total_num
        })
      })
      this.list = list
      // console.log(list)
    }
  }
}
</script>

<style>

</style>
